<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"    
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">

    <!-- INTERFACE -->
    <cc:interface>      
        <cc:attribute name="bill" />  
        <cc:attribute name="duplicate" />
        <cc:attribute name="hosCopy" />
        <cc:attribute name="showProfessional" />
    </cc:interface>

    <!-- IMPLEMENTATION -->
    <cc:implementation>
        <h:outputStylesheet library="css" name="printing.css" />
        <div>
            <p:panel   id="gpBillPreview"  style="margin: auto; padding: 0px; " >
                <div class="fiveinchbill" >

                    <div style="position: absolute!important;left: 58%!important; font-weight: bold!important;
                         top: 0%!important; text-decoration: underline!important;">
                        <h:outputLabel value="Day Case Invoice" style="font-size: 13px!important;"
                                       rendered="#{cc.attrs.bill.patientEncounter.admissionType.admissionTypeEnum eq 'DayCase' 
                                                   and cc.attrs.bill.patientEncounter.admissionType.name eq 'Green Sheet'}"/>
                        <h:outputLabel value="Dialysis Invoice" style="font-size: 13px!important;"
                                       rendered="#{cc.attrs.bill.patientEncounter.admissionType.admissionTypeEnum eq 'DayCase'
                                                   and cc.attrs.bill.patientEncounter.admissionType.name ne 'Green Sheet'}"/>
                    </div>

<!--                    <div style="position: absolute!important;left: 50%!important; font-weight: bold!important;
                         top: 4%!important;">
                        <h:outputLabel value="VAT Reg. No : 114103438-7000" style="font-size: 8px!important;"/>
                    </div>-->

                    <div style="position: absolute;
                         left: 0%!important;
                         top: 7%!important;
                         font-size: 12px!important;">
                        <h:outputLabel value="Final Bill No"/>
                    </div>
                    <div style="position: absolute;
                         left: 26%;
                         top: 7%;
                         font-size:12px!important;">
                        <h:outputLabel value=":"/>
                    </div>
                    <div style="position: absolute;
                         left: 28%!important;
                         top: 7%!important;
                         font-size: 12px!important;">
                        <h:outputLabel value="#{cc.attrs.bill.insId}" />             
                    </div>

                    <div style="position: absolute;
                         left: 71%!important;
                         top: 7%!important;
                         font-size: 12px!important;">
                        <h:outputLabel value="Date"/>
                    </div>
                    <div style="position: absolute;
                         left: 80%;
                         top: 7%;
                         font-size:12px!important;">
                        <h:outputLabel value=":"/>
                    </div>
                    <div style="position: absolute;
                         left: 82%!important;
                         top: 7%!important;
                         font-size: 12px!important;" >
                        <h:outputLabel value="#{cc.attrs.bill.createdAt}" >
                            <f:convertDateTime pattern="dd/MM/yyyy" />
                        </h:outputLabel>

                    </div>

                    <div style="position: absolute;
                         left: 0%!important;
                         top: 11%!important;
                         font-size: 12px!important;">
                        <h:outputLabel value="Payment Type"/>
                    </div>
                    <div style="position: absolute;
                         left: 26%;
                         top: 11%;
                         font-size:12px!important;">
                        <h:outputLabel value=":"/>
                    </div>
                    <div style="position: absolute;
                         left: 28%;
                         top: 11%;
                         font-size:12px!important;" >
                        <h:panelGroup>
                            <h:outputLabel value="#{cc.attrs.bill.patientEncounter.paymentMethod}" />                                
                        </h:panelGroup>
                    </div>

                    <div style="position: absolute;
                         left: 71%!important;
                         top: 11%!important;
                         font-size: 12px!important;">
                        <h:outputLabel value="Time"/>
                    </div>
                    <div style="position: absolute;
                         left: 80%;
                         top: 11%;
                         font-size:12px!important;">
                        <h:outputLabel value=":"/>
                    </div>
                    <div style="position: absolute;
                         left: 82%;
                         top: 11%;
                         font-size:12px!important;" >
                        <h:outputLabel value="#{cc.attrs.bill.createdAt}" >
                            <f:convertDateTime pattern="hh:mm a" />
                        </h:outputLabel>         
                    </div>

                    <div style="position: absolute;
                         left: 0%!important;
                         top: 15%!important;
                         font-size: 12px!important;">
                        <h:outputLabel value="BHT No"/>
                    </div>
                    <div style="position: absolute;
                         left: 26%;
                         top: 15%;
                         font-size:12px!important;">
                        <h:outputLabel value=":"/>
                    </div>
                    <div style="position: absolute;
                         left: 28%;
                         top: 15%;
                         font-size:12px!important;" >
                        <h:outputLabel value="#{cc.attrs.bill.patientEncounter.bhtNo}" />
                    </div>

                    <div style="position: absolute;
                         left: 71%!important;
                         top: 15%!important;
                         font-size: 12px!important;">
                        <h:outputLabel value="P/F/M No" rendered="#{cc.attrs.bill.patient.person.description ne null and cc.attrs.bill.patient.person.description ne ''}"/>
                    </div>
                    <div style="position: absolute;
                         left: 88%;
                         top: 15%;
                         font-size:12px!important;">
                        <h:outputLabel value=":" rendered="#{cc.attrs.bill.patient.person.description ne null and cc.attrs.bill.patient.person.description ne ''}"/>
                    </div>
                    <div style="position: absolute;
                         left: 90%;
                         top: 15%;
                         font-size:12px!important;" >
                        <h:outputLabel value="#{cc.attrs.bill.patient.person.description}" 
                                       rendered="#{cc.attrs.bill.patient.person.description ne null 
                                                   and cc.attrs.bill.patient.person.description ne ''}" />
                    </div>

                    <div style="position: absolute;
                         left: 0%!important;
                         top: 19%!important;
                         font-size: 12px!important;">
                        <h:outputLabel value="Patient Name"/>
                    </div>
                    <div style="position: absolute;
                         left: 26%;
                         top: 19%;
                         font-size:12px!important;">
                        <h:outputLabel value=":"/>
                    </div>
                    <div style="position: absolute;
                         left: 28%;
                         top: 19%;
                         font-size:12px!important;" >
                        <h:outputLabel value="#{cc.attrs.bill.patientEncounter.patient.person.nameWithTitle}" />
                    </div>

                    <div style="position: absolute;
                         left: 0%!important;
                         top: 23%!important;
                         font-size: 12px!important;">
                        <h:outputLabel value="Cr. Company"/>
                    </div>
                    <div style="position: absolute;
                         left: 26%;
                         top: 23%;
                         font-size:12px!important;">
                        <h:outputLabel value=":"/>
                    </div>
                    <div style="position: absolute;
                         left: 28%;
                         top: 23%;
                         font-size:12px!important;" >
                        <h:outputLabel value="#{cc.attrs.bill.patientEncounter.creditCompany.name}" />
                    </div>

                    <div style="position: absolute;
                         left: 0%!important;
                         top: 27%!important;
                         font-size: 12px!important;">
                        <h:outputLabel value="Dialysis No" rendered="#{inwardSearch.reportKeyWord.string ne null and inwardSearch.reportKeyWord.string ne '0'}"/>
                    </div>
                    <div style="position: absolute;
                         left: 26%;
                         top: 27%;
                         font-size:12px!important;">
                        <h:outputLabel value=":" rendered="#{inwardSearch.reportKeyWord.string ne null and inwardSearch.reportKeyWord.string ne '0'}"/>
                    </div>
                    <div style="position: absolute;
                         left: 28%;
                         top: 27%;
                         font-size:12px!important;" >
                        <h:outputLabel value="#{inwardSearch.reportKeyWord.string}" rendered="#{inwardSearch.reportKeyWord.string ne null and inwardSearch.reportKeyWord.string ne '0'}" />
                    </div>

                    <table style="font-size: 11px;
                           position: absolute;
                           left: 0%;
                           top: 32%;
                           width: 100%!important;"  >
                        <tr style="width: 100%!important;">
                            <td style="text-align: left; font-weight: bold;">
                                <h:outputLabel value="Discription" />
                            </td>
                            <td>
                                <h:outputLabel value="" />
                            </td>
                            <td style="text-align: right; font-weight: bold;">
                                <h:outputLabel value="Charge (Rs.)" />
                            </td>
                        </tr>
                        <ui:repeat value="#{cc.attrs.bill.billItems}" var="bip">
                            <h:panelGroup rendered="#{(bip.adjustedValue!=0 and  bip.inwardChargeType ne 'ProfessionalCharge')
                                                      or
                                                      (bip.adjustedValue!=0 and cc.attrs.showProfessional eq true and bip.inwardChargeType eq 'ProfessionalCharge')}">
                                <tr style="width: 100%;"  >
                                    <td style="text-align: left;font-size: 10px!important; width:70%!important;">
                                        <h:outputLabel   value="#{bip.inwardChargeType.label}" />
                                    </td>
                                    <td>

                                    </td>           
                                    <td  style="width: 30%;text-align: right;font-size: 10px!important;">                                        
                                        <h:outputLabel  value="#{bip.adjustedValue}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </td>
                                </tr>
                                <tr style="width: 100%;"  rendered="#{bip.inwardChargeType eq 'ProfessionalCharge' }">

                                    <td style="font-size: 10px!important;width:70%!important;" colspan="3">
                                        <table style="padding-left: 20%!important;">                                             
                                            <ui:repeat value="#{bip.proFees}" var="fe">
                                                <h:panelGroup rendered="#{fe.feeAdjusted ne 0 
                                                                          and fe.bill.cancelled eq false 
                                                                          and fe.bill.billClass eq 'class com.divudi.entity.BilledBill'}">
                                                    <tr>
                                                        <td style="text-align: left;font-size: 8px!important;">
                                                            <h:panelGroup >                       
                                                                #{fe.staff.person.nameWithTitle} 
                                                            </h:panelGroup>
                                                        </td>
                                                        <td  style="text-align: right;font-size: 8px!important;">
                                                            <h:panelGroup>
                                                                <h:outputLabel value="#{fe.feeAdjusted}" style="text-align: right;font-size: 8px!important;">
                                                                    <f:convertNumber pattern="#,##0.00" />
                                                                </h:outputLabel>
                                                            </h:panelGroup>
                                                        </td>
                                                    </tr>
                                                </h:panelGroup>
                                            </ui:repeat>   
                                        </table>
                                    </td>
                                </tr>
                            </h:panelGroup>
                        </ui:repeat>

                        <h:panelGroup>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td style="text-align: right;"><h:outputLabel value="-------------------" /></td>
                            </tr>
                            <h:panelGroup >
                                <!--TOTAL-->
                                <tr style="width: 100%;">
                                    <td style="text-align: left; font-size: 13px!important;font-weight: bold!important;">
                                        <h:outputLabel value="Total"/>
                                    </td>
                                    <td>&nbsp;</td>
                                    <td style="text-align: right;font-size: 13px!important;font-weight: bold!important;">

                                        <h:outputLabel rendered="#{cc.attrs.showProfessional}" value="#{cc.attrs.bill.grantTotal}" >
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>  

                                        <h:outputLabel rendered="#{!cc.attrs.showProfessional}" value="#{cc.attrs.bill.hospitalFee}" >
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>  

                                    </td>
                                </tr>
                            </h:panelGroup> 
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td style="text-align: right;"><h:outputLabel value="-------------------" /></td>
                            </tr>
                        </h:panelGroup>

                        <h:panelGroup rendered="#{cc.attrs.bill.discount ne 0.0}">
                            <!--DISCOUNT-->
                            <tr>
                                <td style="text-align: left;font-size: 13px!important;font-weight: bold!important;">
                                    <h:outputLabel  rendered="#{cc.attrs.bill.discount ne 0.0}" value="Discount"/>
                                </td>
                                <td>&nbsp;</td>
                                <td style="text-align: right;font-size: 13px!important;font-weight: bold!important;">
                                    <h:outputLabel rendered="#{cc.attrs.bill.discount ne 0.0}"   value="(#{cc.attrs.bill.discount})" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </td>
                            </tr>
                        </h:panelGroup>

                        


                        <h:panelGroup >
                            <!--PAID-->
                            <tr>
                                <td style="text-align: left;font-size: 13px!important;font-weight: bold!important;">
                                    <h:outputLabel   value="Paid By Patient " rendered="#{cc.attrs.bill.paidAmount !=0}"/>
                                </td>
                                <td>
                                    <!--                                    <table>
                                                                            <ui:repeat value="#{cc.attrs.bill.backwardReferenceBills}" var="b">
                                                                                <h:panelGroup rendered="#{(b.netTotal ne 0 )                                                                       
                                                              and                                                                        
                                                              ((b.cancelled eq false 
                                                              and b.billClass eq 'class com.divudi.entity.BilledBill')
                                                              or 
                                                              (b.cancelled eq false 
                                                              and b.refundedBill eq null
                                                              and b.billClass eq 'class com.divudi.entity.RefundBill'))}" >
                                        <tr>
                                            <td>
                                    #{b.insId}
                                </td>
                                <td>
                                    <h:outputLabel value="#{b.netTotal}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </td>
                            </tr>
                        </h:panelGroup>
                    </ui:repeat>
                </table>-->
                                </td>
                                <td style="text-align: right;font-size: 13px!important;font-weight: bold!important;">
                                    <h:outputLabel  value="#{cc.attrs.bill.paidAmount+cc.attrs.bill.patientEncounter.creditPaidAmount}" rendered="#{cc.attrs.bill.paidAmount !=0}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </td>
                            </tr>

                            <tr>

                                <td colspan="3">
                                    <table style="padding-left: 20%!important;">
                                        <ui:repeat value="#{cc.attrs.bill.backwardReferenceBills}" var="b">
                                            <h:panelGroup rendered="#{(b.netTotal ne 0 )                                                                       
                                                                      and                                                                        
                                                                      ((b.cancelled eq false 
                                                                      and b.billClass eq 'class com.divudi.entity.BilledBill')
                                                                      or 
                                                                      (b.cancelled eq false 
                                                                      and b.refundedBill eq null
                                                                      and b.billClass eq 'class com.divudi.entity.RefundBill'))}" >
                                                <tr>
                                                    <td>
                                                        #{b.insId}
                                                    </td>
                                                    <td>
                                                        <h:outputLabel value="#{b.netTotal}" style="float: right!important;">
                                                            <f:convertNumber pattern="#,##0.00" />
                                                        </h:outputLabel>
                                                    </td>
                                                </tr>
                                            </h:panelGroup>
                                        </ui:repeat>
                                    </table>
                                </td>

                            </tr>


                        </h:panelGroup>

                        <h:panelGroup >
                            <!--DUE AMOUNT-->
                            <tr>
                                <td style="text-align: left;font-size: 13px!important;font-weight: bold!important;">
                                    <h:outputLabel   value="Due Amount"/>
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                                <td style="text-align: right;font-size: 13px!important;font-weight: bold!important;">
                                    <h:outputLabel  value="#{cc.attrs.bill.netTotal-cc.attrs.bill.paidAmount+cc.attrs.bill.patientEncounter.creditPaidAmount}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </td>
                            </tr>


                        </h:panelGroup>
                        <h:panelGroup >
                            <!--DUE AMOUNT-->
                            <tr>
                                <td style="text-align: left;font-size: 13px!important;font-weight: bold!important;">
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                                <td style="text-align: right;font-size: 13px!important;font-weight: bold!important;">
                                    &nbsp;
                                </td>
                            </tr>


                        </h:panelGroup>
                        <h:panelGroup >
                            <!--DUE AMOUNT-->
                            <tr>
                                <td colspan="2" style="text-align: left;font-size: 13px!important;text-decoration: overline;">
                                    <h:outputLabel value="Patient/Guardian" />
                                </td>

                                <td style="text-align: right;font-size: 13px!important;text-decoration: overline;">
                                    <h:outputLabel value="Cashier : #{cc.attrs.bill.creater.code}" />
                                </td>
                            </tr>


                        </h:panelGroup>



                    </table>

<!--                    <h:outputLabel value="Cashier : #{cc.attrs.bill.creater.code}" styleClass="cashierGSPrinting">
                    </h:outputLabel>

                    <h:outputLabel value="Patient/Guardian" styleClass="guardianGSPrinting">
                    </h:outputLabel>-->

<!--                    <div style="position: absolute;
                         left: 0%;
                         bottom:  1%;
                         font-size:10px!important;" rendered="#{sessionController.userPreference.applicationInstitution eq 'Ruhuna'}" >
                        <h:outputLabel value="#{cc.attrs.bill.netTotal-cc.attrs.bill.paidAmount+cc.attrs.bill.patientEncounter.creditPaidAmount}" >
                            <f:convertNumber pattern="******0.00" />
                        </h:outputLabel>
                    </div>
                    <div style="position: absolute;
                         right:  0%;
                         bottom:  1%;
                         font-size:10px!important;" rendered="#{sessionController.userPreference.applicationInstitution eq 'Ruhuna'}" >
                        <h:outputLabel  value="#{cc.attrs.bill.paidAmount+cc.attrs.bill.patientEncounter.creditPaidAmount}" rendered="#{cc.attrs.bill.paidAmount !=0}" >
                            <f:convertNumber pattern="******0.00" />
                        </h:outputLabel>
                    </div>-->
                </div>


            </p:panel>
        </div>
    </cc:implementation>
</html>